<?php
require_once ("includes/connect.php");
require_once ("includes/function.php");

$task = $_REQUEST["task"];
$cheque_no = $_REQUEST["cheque_no"];
$tblname = $_REQUEST["tblname"];
?>

<script type="text/javascript">
    $(document).ready(function() {
        $("#i_date").datepicker({
            dateFormat: "yy-mm-dd",
            showButtonPanel: true
        });

        $("#save_menus").click(function() {
            event.preventDefault();

            var i_date = $("#i_date").val();
            var task = "<?php echo $task; ?>";
            var cheque_no = "<?php echo $cheque_no; ?>";
            var tblname = "<?php echo $tblname; ?>";

            switch (tblname) {
                case "tbl_pet":
                    var file_process = "cheque_process.php";
//                    var pages = "cheque_manage";
                    break;

                case "tbl_petition":
                    var file_process = "cheque_process_petition.php";
//                    var pages = "cheque_manage";
                    break;

                case "tbl_salary":
                    var file_process = "cheque_process_salary.php";
//                    var pages = "cheque_manage";
                    break;

            }
            $.post(file_process, {task: task, i_date: i_date, cheque_no: cheque_no}, function(data) {
                //$("#test").html(data);
                window.location.href = "index.php?pages=cheque_manage&tblname=" + tblname;
//                if (task == "approvedCheque") {
//                    window.location.href = "index.php?pages=paid";
//                } else if (task == "approved") {
//                    window.location.href = "index.php?pages=finance";
//                }
            });
        });
    });
</script>

<div id="test"></div>
<p>
    <label>วันที่</label>
    <input class="span3" type="text" id="i_date" name="i_date" />
<?php
$config = get_config();

?>
    เช็คหมดอายุอีก <?=$config["cheque_expire"] ?> วัน นับจากวันที่อนุมัติ
</p>
<div class="form-actions">
    <input type="hidden" id="tblname" name="tblname" value="<?php echo $tblname; ?>">
    <button class="btn btn-primary" id="save_menus">บันทึก</button>
    <a class="btn close-dialog"><i class="icon-remove"></i> ยกเลิก</a>

</div>
